#include <bits/stdc++.h>

using namespace std;

const int MAXN = 110;
const int mod = 1e9+7;

int n;
long long k;

struct matrix{
	long long arr[MAXN][MAXN];
	matrix(){memset(arr,0,sizeof(arr));}
	long long * operator [](long long x){return arr[x];}
	const long long * operator [](long long x)const{return arr[x];}
	friend matrix operator * (matrix x,matrix y){
		matrix ans;
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++)
				if(x[i][j])
					for(int k = 1;k <= n;k++)
						(ans[i][k] += x[i][j] * y[j][k] % mod) %= mod;
		return ans;
	}
}a,b;

int main (){
	scanf("%d %lld",&n,&k);
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			scanf("%lld",&a[i][j]);
	for(b=a,--k;k;k>>=1,b=b*b) if(k&1) a = a * b;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++)
			printf("%lld ",a[i][j]);
		puts("");
	}
	return 0;
}
